package com.gsnd.briuppts.web.controller;

import com.github.pagehelper.PageInfo;
import com.gsnd.briuppts.Result.Response;
import com.gsnd.briuppts.entity.Do.ManagerFenceHouseExtend;
import com.gsnd.briuppts.entity.ManagerFenceHouse;
import com.gsnd.briuppts.service.ManagerFHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/fenceHouse")
public class ManagerFHController {
    @Autowired
    ManagerFHService managerFHService;
    @GetMapping
    public Response<PageInfo<ManagerFenceHouse>> findAllFHByPage(String fhName,
                                    Integer pageNum,
                                    Integer pageSize){
        PageInfo<ManagerFenceHouse> PageInfo =
                managerFHService.findAllByConditionByPage(fhName, pageNum, pageSize);
        return Response.success(PageInfo);
    }
    @PostMapping("/saveOrUpdate")
    public Response<String> saveOrUpdateFh(@RequestBody ManagerFenceHouse managerFenceHouse){
        managerFHService.addAndEdit(managerFenceHouse);
        return Response.success("新增/修改成功");
    }
    @DeleteMapping("/{id}")
    public Response<String> removeById(@PathVariable String id){
        List<String> list= Collections.singletonList(id);
        managerFHService.removeByIdOrAll(list);
        return Response.success("批量删除成功");
    }
    @DeleteMapping("/deleteByIdAll")
    public Response<String> removeByIds(@RequestBody List<String> ids){
        managerFHService.removeByIdOrAll(ids);
        return Response.success("批量删除成功");
    }

    @GetMapping("/{fhId}")
    public Response<ManagerFenceHouseExtend> findDetailByFhId(@PathVariable String fhId){
        ManagerFenceHouseExtend detailByFhId=managerFHService.findDetailByFhId(fhId);
        return Response.success(detailByFhId);
    }

    @GetMapping("/queryAll")
    public Response queryAll() {
        return Response.success(managerFHService.findAll());
    }

}
